import React, { useEffect, useState } from "react";
import "./common.less";
import { Breadcrumb, Layout, Menu } from "antd";
import HeaderContent from "../components/header/HeaderContent.jsx";
import ContentRouter from "./ContentRouter";
import { message } from "antd";
import { isAuthenticated } from "../utils/auth";
import { Switch, useHistory, useLocation } from "react-router-dom";
import LeftMenu from "../components/leftsider/LeftMenu";
const { Content } = Layout;
const HomePage = (props) => {
  const [isLogin, setIsLogin] = useState(false);
  const [curPath, setCurPath] = useState("");
  const [pathArr, setPathArr] = useState(["home"]);
  const history = useHistory();
  const location = useLocation();
  const renderPath = (location) => {
    let fullPathName = location.pathname.split("/");
    if (fullPathName.length > 0) {
      setPathArr(fullPathName);
    }
  };
  const checkLoginStatus = () => {
    if (!isAuthenticated) {
      history.push("/login");
    } else {
      setIsLogin(true);
    }
  };
  useEffect(() => {
    checkLoginStatus();
    setCurPath(location.pathname);
    const unlisten = history.listen((location) => {
      renderPath(location);
    });
    return () => {
      unlisten();
    };
  }, [history]);

  return (
    <Layout>
      <HeaderContent></HeaderContent>
      <Layout style={{display:'block'}}>
        <LeftMenu />
        <Layout style={{ padding: "0 24px 24px" }} className="contentStyle">
          <Breadcrumb style={{ margin: "16px 0",paddingLeft: "10"}}>
            {pathArr.map((data, i) => (
              <Breadcrumb.Item key={data}><h3>{data}</h3></Breadcrumb.Item>
            ))}
          </Breadcrumb>
          <Content
            className="site-layout-background"
            style={{
              padding: 24,
              margin: 0,
              minHeight: 580,
            }}
          >
            <Switch>
              <ContentRouter />
            </Switch>
          </Content>
        </Layout>
      </Layout>
    </Layout>
  );
};

export default HomePage;
